<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>highlight.asm-mips</title>
<meta name="generator" content="KF5::SyntaxHighlighting - Definition (MIPS Assembler) - Theme (Breeze Light)"/>
</head><body style="background-color:#ffffff;color:#1f1c1b"><pre>
<span style="color:#898887;"># A demonstration of some simple MIPS instructions</span>
<span style="color:#898887;"># used to test QtSPIM</span>

	<span style="color:#898887;"># Declare main as a global function</span>
	<span style="color:#0057ae;">.globl</span> main 

	<span style="color:#898887;"># All program code is placed after the</span>
	<span style="color:#898887;"># .text assembler directive</span>
	<span style="font-weight:bold;">.text</span> 		

<span style="color:#898887;"># The label 'main' represents the starting point</span>
<span style="color:#006e28;">main:</span>
	<span style="color:#644a9b;">li</span> <span style="color:#0000ff;">$t2</span>, <span style="color:#b08000;">25</span>		<span style="color:#898887;"># Load immediate value (25) </span>
	<span style="font-weight:bold;">lw</span> <span style="color:#0000ff;">$t3</span>, value		<span style="color:#898887;"># Load the word stored in value (see bottom)</span>
	<span style="font-weight:bold;">add</span> <span style="color:#0000ff;">$t4</span>, <span style="color:#0000ff;">$t2</span>, <span style="color:#0000ff;">$t3</span>	<span style="color:#898887;"># Add</span>
	<span style="font-weight:bold;">sub</span> <span style="color:#0000ff;">$t5</span>, <span style="color:#0000ff;">$t2</span>, <span style="color:#0000ff;">$t3</span>	<span style="color:#898887;"># Subtract</span>
	<span style="font-weight:bold;">sw</span> <span style="color:#0000ff;">$t5</span>, Z		<span style="color:#898887;">#Store the answer in Z (declared at the bottom)  </span>

	<span style="color:#898887;"># Exit the program by means of a syscall.</span>
	<span style="color:#898887;"># There are many syscalls - pick the desired one</span>
	<span style="color:#898887;"># by placing its code in $v0. The code for exit is &quot;10&quot;</span>
	<span style="color:#644a9b;">li</span> <span style="color:#0057ae;">$v0</span>, <span style="color:#b08000;">10</span> <span style="color:#898887;"># Sets $v0 to &quot;10&quot; to select exit syscall</span>
	<span style="font-weight:bold;">syscall</span> <span style="color:#898887;"># Exit</span>

	<span style="color:#898887;"># All memory structures are placed after the</span>
	<span style="color:#898887;"># .data assembler directive</span>
	<span style="font-weight:bold;">.data</span>

	<span style="color:#898887;"># The .word assembler directive reserves space</span>
	<span style="color:#898887;"># in memory for a single 4-byte word (or multiple 4-byte words)</span>
	<span style="color:#898887;"># and assigns that memory location an initial value</span>
	<span style="color:#898887;"># (or a comma separated list of initial values)</span>
<span style="color:#006e28;">value:</span>	<span style="color:#0057ae;">.word</span> <span style="color:#b08000;">12</span>
<span style="color:#006e28;">Z:</span>	<span style="color:#0057ae;">.word</span> <span style="color:#b08000;">0</span>
</pre></body></html>
